package raceReservationServer.raceServerGateway;

import java.util.List;
import org.omg.CosNaming.NamingContextExt;
import org.omg.CosNaming.NamingContextExtHelper;

import corbaServer.corba.ICorbaServer;
import corbaServer.corba.ICorbaServerHelper;

public class RaceServerGatewayFactory {

	/**
	 * ADD your code here; this class must be a SINGLETON String serviceUri =
	 * ip, port and name of the service String serverTech = technology of the
	 * server, 'corba' or 'ws'
	 */
	private RaceServerGatewayFactory(){
		
	}
	
	private static RaceServerGatewayFactory instance;
	
	public static RaceServerGatewayFactory getInstance(){
		if(instance == null){
			instance= new RaceServerGatewayFactory();
		}
		return instance;
	}
	
	public IRaceServerGateway getRaceServerGateway(String serviceUri, String serverTech) {
		IRaceServerGateway the_gateway = null;
		System.out.println("The uri used to create the gateway: " + serviceUri);
		System.out.println("The technology used to create the gateway: " + serverTech);
		if (serverTech=="corba"){
			the_gateway= new CorbaRaceServerGateway(serviceUri);
		}
		if (serverTech=="ws"){
			the_gateway= new WSRaceServerGateway(serviceUri);
		}
		if (serverTech=="jms"){
			String aux= serviceUri.split(" ")[2];
			System.out.println("The value for jms gateway: " + aux);
			the_gateway= new JMSRaceServerGateway(aux);
		}
		
		return the_gateway;
	}
	
	
}
